<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\xiang;

class xiangController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(){
    $user = xiang::paginate(100);
     return view('index2',['user'=>$user]);
   }

   public function Doxiang(Request $request)
   {

       $user = new xiang;

         $name =  $user ->name = $request->name;
         $intro = $user ->intro =$request->intro;
         if($request->hasFile('img')) {
            //创建文件的名字
            $filename = time().rand(10000,99999);
            //获取文件的后缀
            $suffix = $request->file('img')->getClientOriginalExtension();
            //文件夹
            $dirname = './uploads/';

           
            //文件名
            $file = $filename .'.'. $suffix;

            //移动
            $request->file('img')->move($dirname,$file);
             $dirname = trim($dirname,'.');
            //修改图片属性
           $res =  $user->img = $dirname.$file;

        }

        $users = xiang::insert([
          'name' => $name,
          'intro'=> $intro,
          'img' => $res,
          ]);
     return back();  
   }
    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
